package com.learn.order.rest.api;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@RestController
@DefaultProperties(defaultFallback = "defaultFallback")
public class HystrixController {

//	@HystrixCommand(
//			fallbackMethod="fallback",
//			commandProperties = { 
//			@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "120000"),
//			@HystrixProperty(name = "circuitBreaker.enabled", value = "true"),
//			@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
//			@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "2000"),
//			@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60")})
	@HystrixCommand
	@GetMapping("hystrixtest")
	public String hystrix(@RequestParam("flag") boolean flag) {
		if(flag)  throw new RuntimeException("异常");
		return "success";
	}

	String fallback() {
		return "hello hystrix";
	}
	
	String defaultFallback() {
		return "hello hystrix";
	}

}
